package com.example.tdj;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.GroundOverlayOptions;
import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.Overlay;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.PolylineOptions;
import com.baidu.mapapi.map.TextOptions;
import com.baidu.mapapi.model.LatLng;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

public class ShowTrackActivity extends AppCompatActivity {

    private MapView mMapView;
    private BaiduMap mBaiduMap;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SDKInitializer.initialize(getApplicationContext());
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_track);
        init();
    }

    public void init(){
        mMapView = findViewById(R.id.mapview);
        mBaiduMap = mMapView.getMap();

        LatLng current = new LatLng(30.54280268,114.3695334);
        MapStatus mapStatus = new MapStatus.Builder()
                .target(current).zoom(18).build();
        MapStatusUpdate update = MapStatusUpdateFactory.newMapStatus(mapStatus);
        mBaiduMap.setMapStatus(update);
        showTrack(mBaiduMap);
    }

    /**
     * 显示轨迹方法
     * @param baiduMap
     */
    public void showTrack(BaiduMap baiduMap){
        List<LatLng> points = new ArrayList<>();
        LatLng pt1 = new LatLng(30.53312,114.367442);//青楼
        LatLng pt2 = new LatLng(30.543559,114.369512);//万林
        LatLng pt3 = new LatLng(30.543213,114.37625);

        points.add(pt1);
        points.add(pt2);
        points.add(pt3);

        OverlayOptions options = new PolylineOptions()
                .width(15)
                .dottedLine(true)
                .color(Color.BLUE)
                .points(points);
        baiduMap.addOverlay(options);

        View view = View.inflate(getApplicationContext(),R.layout.bike_data,null);
        InfoWindow window = new InfoWindow(view, pt1, 0);
        baiduMap.showInfoWindow(window);
    }

    @Override
    protected void onPause() {
        super.onPause();
        // activity 暂停时同时暂停地图控件
        mMapView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        // activity 恢复时同时恢复地图控件
        mMapView.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // activity 销毁时同时销毁地图控件
        mMapView.onDestroy();
    }
}
